package com.boco.blch.analysiser.compliance.HW.manager;



import com.boco.blch.analysiser.compliance.ComplianceResolved;
import com.boco.blch.analysiser.util.XmlUtil;

/**
 * @author 黄戈
 * HBase数据存储列族加密安全基线要求项
 *
 */

public class BOCO_Hbase_DataEncryptProtect_DataStorageEncrypt implements ComplianceResolved {
	
	private final static String HbaseP1 ="hbase.regionserver.wal.encryption";
	private final static String HbaseP2="hbase.crypto.keyprovider.parameters";
	private final static String HbaseP3="hbase.crypto.keyprovider";
	private final static String HbaseP4="hbase.crypto.master.key.name";
	private final static String HbaseP5="hfile.format.version";
	private final static String HbaseP6="hbase.regionserver.hlog.reader.impl";
	private final static String HbaseP7="hbase.regionserver.hlog.writer.impl";
	private final static String HbaseR1="org.apache.hadoop.hbase.io.crypto.KeyStoreKeyProvider";
	private final static String HbaseR2="org.apache.hadoop.hbase.regionserver.wal.SecureProtobufLogReader";
	private final static String HbaseR3="org.apache.hadoop.hbase.regionserver.wal.SecureProtobufLogWriter";

	@Override
	public int realEchoResolved(String echoResult) {
		if(!echoResult.equals("")&&echoResult!= null&&(!echoResult.contains(NoPermission1)&&!echoResult.contains(NoPermission2)&&!echoResult.contains(NoPermission3))){
			String ManagerResult=echoResult;//.substring(echoResult.indexOf("manager-start")+"manager-start".length(),echoResult.indexOf("manager-end")).trim();
			if(!ManagerResult.contains(NotFindFile)&&!ManagerResult.contains("boco-HBase-result:error")){//判断有无目录
				String HbaseResult1=XmlUtil.getValueByName(ManagerResult,HbaseP1);
				String HbaseResult2=XmlUtil.getValueByName(ManagerResult,HbaseP2);
				String HbaseResult3=XmlUtil.getValueByName(ManagerResult,HbaseP3);
				String HbaseResult4=XmlUtil.getValueByName(ManagerResult,HbaseP4);
				String HbaseResult5=XmlUtil.getValueByName(ManagerResult,HbaseP5);
				String HbaseResult6=XmlUtil.getValueByName(ManagerResult,HbaseP6);
				String HbaseResult7=XmlUtil.getValueByName(ManagerResult,HbaseP7);
				if(HbaseResult1.equals("true")&&HbaseResult2.contains(".jks")&&HbaseResult3.equals(HbaseR1)&&
				   HbaseResult4.equals("omm")&&HbaseResult5.equals("3")&&HbaseResult6.equals(HbaseR2)&&HbaseResult7.equals(HbaseR3)){
					return SUCCESS;
				}else {
					return FAILED;
				}
			}else{//没安装，合规
				return FAILED;
			}
		}else{
			return FAILED;
		}
	
	}

}
